
import EmptyUtils from './EmptyUtils.js'

export default class NetUtils {

  static GET = 'GET'
  static POST = 'POST'

  static R(url, data, successFuc, errorFunc, method) {
    if (EmptyUtils.isE(url)) return

    method = EmptyUtils.E(method, NetUtils.GET)

    wx.request({
      url: url,
      method: method,
      data: data,
      success: function (res) {
        res = res.data

        let code = res.code
        let data = res.data
        if (code === 0) {

          if (typeof successFuc !== 'function' || successFuc === 'undefined') return
          successFuc(data)
        } else { 

          if (typeof errorFunc !== 'function' || errorFunc === 'undefined') return
          errorFunc(res)
        }
        
      },
      fail: function (res) {
      
      },
    })
  }
}